//
//  list4ViewController.m
//  225视听百科
//
//  Created by 张元阳(10) on 14-12-30.
//  Copyright (c) 2014年 lanou3g.com 蓝鸥科技. All rights reserved.
//

#import "list4ViewController.h"
#import "CustomTableViewCell.h"
#import "ConnectModel.h"
#import "UIImageView+WebCache.h"
#import "List5ViewController.h"

@interface list4ViewController ()<UITableViewDataSource, UITableViewDelegate>

@end

@implementation list4ViewController
- (void)dealloc
{
    [_table release];
    [_list4Array release];
    [super dealloc];
}
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.list4Array = [NSMutableArray array];
    }
    return self;
}


- (void)viewDidLoad {
    self.view.backgroundColor = [UIColor whiteColor];
    [super viewDidLoad];
    [self createTable];
}
- (void)createTable
{
    NSString *str = [NSString stringWithFormat:@"http://app.9nali.com/777/albums/%ld?page_id=1&isAsc=true&device=iPhone&version=1.1.5", self.Id];
    [ConnectModel connectModelWithUrl:str parmaters:nil finished:^(NSData *getData) {
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:getData options:NSJSONReadingMutableLeaves error:nil];
        NSDictionary *dicc = [dic objectForKey:@"tracks"];
        NSMutableArray *array = [dicc objectForKey:@"list"];
        [_list4Array addObjectsFromArray:array];
        [_table reloadData];
    }];
    
    
    self.table = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 113) style:UITableViewStylePlain];
    _table.rowHeight = 80;
    _table.dataSource = self;
    _table.delegate = self;
    [_table registerClass:[CustomTableViewCell class] forCellReuseIdentifier:@"cell"];
    [self.view addSubview:_table];
    [_table release];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [_list4Array count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSDictionary *dic = [_list4Array objectAtIndex:indexPath.row];
    CustomTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    NSString *image = [dic objectForKey:@"coverLarge"];
    [cell.imageV1 setImageWithURL:[NSURL URLWithString:image]];
    cell.label1.text = [dic objectForKey:@"title"];

    cell.label2.text = @"一年前";
    
    
    
    NSInteger time = [[dic objectForKey:@"playtimes"] integerValue];
    NSString *ti = [NSString stringWithFormat:@"%ld", time];
    cell.label3.text = ti;
    
    NSInteger dur = [[dic objectForKey:@"duration"] integerValue];
    CGFloat duration = dur / 60.0f;
    NSString *du = [NSString stringWithFormat:@"%f", duration];
    NSString *du1 = [du substringToIndex:5];
    NSString *du2 = [du1 stringByReplacingOccurrencesOfString:@"." withString:@":"];
    cell.label4.text = du2;
    
    NSInteger mp = [[dic objectForKey:@"mp3size_32"] integerValue];
    CGFloat mp1 = mp / 1024 / 1024.0f;
    NSString *mp2 = [NSString stringWithFormat:@"%f", mp1];
    NSString *mp3 = [mp2 substringToIndex:3];
    NSString *mp4 = [NSString stringWithFormat:@"%@M", mp3];
    cell.label5.text = mp4;
    
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
